package com.deliveryservicesystem.service;

import com.deliveryservicesystem.app.exceptions.NonexistentEntityException;
import com.deliveryservicesystem.app.exceptions.PreexistingEntityException;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;

/**
 * File Name: CrudServiceTemplate.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.service
 * Author: Lance
 * Date: Jun 20, 2012
 * Editor:
 *
 * @param <TYPE> the model type to apply to the templet
 */
public interface CrudServiceTemplate<TYPE> extends Serializable
{

    /**
     * Create a new entity in database
     *
     * @param enitiy to create
     * @throws PreexistingEntityException
     * @throws Exception
     */
    void create(TYPE enitiy) throws PreexistingEntityException, Exception;

    /**
     * Delete an existing entity from database
     *
     * @param id of the entity to delete
     * @throws NonexistentEntityException
     */
    void destroy(Integer id) throws NonexistentEntityException;

    /**
     * Edit an entity in database
     *
     * @param enitiy to edit
     * @throws NonexistentEntityException
     * @throws Exception
     */
    void edit(TYPE enitiy) throws NonexistentEntityException, Exception;

    /**
     * Find entity by id
     *
     * @param id of the entity to find
     * @return found entity
     */
    TYPE findById(Integer id);

    /**
     * Find entities
     *
     * @return List of entities
     */
    List<TYPE> findEntities();

    /**
     * Find entities in range
     *
     * @param maxResults upper range
     * @param firstResult lower range
     * @return List of entities in range
     */
    List<TYPE> findEntities(int maxResults, int firstResult);

    /**
     * Find the total number of entities
     *
     * @return count
     */
    int count();

    /**
     * Get the entity manager for the service
     *
     * @return EntityManager
     */
    EntityManager getEntityManager();
}